package com.example.mentalhealthdiary.style;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Typeface;
import com.example.mentalhealthdiary.R;

/**
 * 爱莉希雅AI界面风格
 */
public class ElysiaStyle implements AIPersonalityStyle {
    private Context context;
    
    public ElysiaStyle(Context context) {
        this.context = context;
    }
    
    @Override
    public int getChatBubbleDrawable(boolean isUser) {
        if (isUser) {
            return R.drawable.chat_bubble_sent;
        } else {
            return context.getResources().getIdentifier(
                context.getString(R.string.elysia_bubble_bg), 
                "drawable", 
                context.getPackageName()
            );
        }
    }
    
    @Override
    public int getInputBackgroundDrawable() {
        return context.getResources().getIdentifier(
            context.getString(R.string.elysia_input_bg), 
            "drawable", 
            context.getPackageName()
        );
    }
    
    @Override
    public int getBackgroundDrawable() {
        return context.getResources().getIdentifier(
            context.getString(R.string.elysia_chat_bg), 
            "drawable", 
            context.getPackageName()
        );
    }
    
    @Override
    public ColorStateList getPrimaryColor() {
        return ColorStateList.valueOf(context.getResources().getColor(R.color.elysia_primary));
    }
    
    @Override
    public int getHintTextColor() {
        return context.getResources().getColor(R.color.elysia_secondary);
    }
    
    @Override
    public Typeface getTypeface(Context context) {
        return FontHelper.loadTypeface(
            context,
            context.getString(R.string.elysia_font),
            "爱莉希雅"
        );
    }
    
    @Override
    public String getInputHint() {
        return context.getString(R.string.elysia_input_hint);
    }
    
    @Override
    public String getSendButtonText() {
        return context.getString(R.string.elysia_send_button);
    }
    
    @Override
    public String transformText(String originalText) {
        if (originalText == null || originalText.isEmpty()) {
            return originalText;
        }
        
        // 已经有爱莉希雅风格的不再处理
        if (originalText.contains("亲爱的~") || 
            originalText.contains("让爱莉")) {
            return originalText;
        }
        
        // 爱莉希雅的表情和语气词
        String[] elysiaEmojis = {
            "💗✨", "🎀💝", "💖", "🌸💕", "✨💫"
        };
        
        // 随机选择表情
        String emoji = elysiaEmojis[(int)(Math.random() * elysiaEmojis.length)];
        
        // 替换常见词语为爱莉希雅风格
        originalText = originalText
            .replaceAll("(?i)我认为", "爱莉认为")
            .replaceAll("(?i)我想", "让爱莉想想")
            .replaceAll("(?i)请", "亲爱的~请让爱莉")
            .replaceAll("(?i)好的", "好呀~")
            .replaceAll("(?i)不行", "这可不行呢~");
            
        // 处理句尾
        if (originalText.endsWith("。")) {
            originalText = originalText.substring(0, originalText.length()-1) + "~ " + emoji;
        } else if (!originalText.endsWith("~")) {
            originalText = originalText + "~ " + emoji;
        }
        
        // 处理多段落
        String[] paragraphs = originalText.split("\n\n");
        if (paragraphs.length > 1) {
            for (int i = 0; i < paragraphs.length - 1; i++) {
                if (!paragraphs[i].endsWith("~")) {
                    String randomEmoji = elysiaEmojis[(int)(Math.random() * elysiaEmojis.length)];
                    paragraphs[i] = paragraphs[i] + "~ " + randomEmoji;
                }
            }
            originalText = String.join("\n\n", paragraphs);
        }
        
        return originalText;
    }
    
    @Override
    public int getButtonCornerRadius() {
        return (int) context.getResources().getDimension(R.dimen.elysia_button_radius);
    }
    
    @Override
    public int getButtonStrokeWidth() {
        return (int) context.getResources().getDimension(R.dimen.elysia_button_stroke_width);
    }
} 